<!DOCTYPE html>
<html lang="en-us">
<head>
	<meta charSet="UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1" />
	<link rel="apple-touch-icon" sizes="57x57" href="/CsvHelper/favicons/apple-icon-57x57.png" />
	<link rel="apple-touch-icon" sizes="60x60" href="/CsvHelper/favicons/apple-icon-60x60.png" />
	<link rel="apple-touch-icon" sizes="72x72" href="/CsvHelper/favicons/apple-icon-72x72.png" />
	<link rel="apple-touch-icon" sizes="76x76" href="/CsvHelper/favicons/apple-icon-76x76.png" />
	<link rel="apple-touch-icon" sizes="114x114" href="/CsvHelper/favicons/apple-icon-114x114.png" />
	<link rel="apple-touch-icon" sizes="120x120" href="/CsvHelper/favicons/apple-icon-120x120.png" />
	<link rel="apple-touch-icon" sizes="144x144" href="/CsvHelper/favicons/apple-icon-144x144.png" />
	<link rel="apple-touch-icon" sizes="152x152" href="/CsvHelper/favicons/apple-icon-152x152.png" />
	<link rel="apple-touch-icon" sizes="180x180" href="/CsvHelper/favicons/apple-icon-180x180.png" />
	<link rel="icon" type="image/png" sizes="192x192" href="/CsvHelper/favicons/android-icon-192x192.png" />
	<link rel="icon" type="image/png" sizes="32x32" href="/CsvHelper/favicons/favicon-32x32.png" />
	<link rel="icon" type="image/png" sizes="96x96" href="/CsvHelper/favicons/favicon-96x96.png" />
	<link rel="icon" type="image/png" sizes="16x16" href="/CsvHelper/favicons/favicon-16x16.png" />
	<link rel="manifest" href="/CsvHelper/manifest.json" />
	<meta name="msapplication-TileColor" content="#ffffff" />
	<meta name="msapplication-TileImage" content="/ms-icon-144x144.png" />
	<meta name="theme-color" content="#ffffff" />
	<title>V20 | CsvHelper</title>

	
	
		<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.9.1/css/bulma.min.css" />
	
	<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/default.min.css" />
	<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/vs.min.css" />
	<link rel="stylesheet" href="/CsvHelper/styles/index.css" />

	<script defer src="https://use.fontawesome.com/releases/v5.14.0/js/all.js"></script>
	<script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/highlight.min.js"></script>
</head>
<body>
	<header id="header" class="header">
	<nav class="navbar is-light">
		<div class="navbar-brand">
			<a class="navbar-item" href="/CsvHelper">
				<img src="/CsvHelper/images/logo.svg" width="66" height="28" />
			</a>
			<div id="navbar-burger" class="navbar-burger">
				<span></span>
				<span></span>
				<span></span>
			</div>
		</div>
		<div id="navbar-menu" class="navbar-menu">
			<div class="navbar-start">
				<a class="navbar-item" href="/CsvHelper/getting-started">Getting Started</a>
				<a class="navbar-item" href="/CsvHelper/examples">Examples</a>
				<a class="navbar-item" href="/CsvHelper/migration">Migration</a>
				<a class="navbar-item" href="/CsvHelper/change-log">Change Log</a>
			</div>
			<div class="navbar-end">
				<a class="navbar-item" href="https://twitter.com/JoshClose">
					<span class="icon">
						<i class="fab fa-twitter"></i>
					</span>
				</a>
				<a class="navbar-item" href="https://github.com/JoshClose/CsvHelper">
					<span class="icon">
						<i class="fab fa-github"></i>
					</span>
				</a>
			</div>
		</div>
	</nav>
</header>


	<main id="main" class="container is-fluid">
		<div class="columns is-variable is-1">
				<div class="column">
					<div class="content">
						<h1 id="migrating-from-version-19-to-20">Migrating from version 19 to 20</h1>
<h2 id="convertusing">ConvertUsing</h2>
<p><code>ConvertUsing</code> was renamed to <code>Convert</code>.</p>
<pre><code class="language-cs">// v19
Map(m =&gt; m.Property).ConvertUsing(row =&gt; row.GetField&lt;int&gt;(0) + row.GetField&lt;int&gt;(1));

// v20
Map(m =&gt; m.Property).Convert(row =&gt; row.GetField&lt;int&gt;(0) + row.GetField&lt;int&gt;(1));
</code></pre>
<h2 id="csvconfiguration">CsvConfiguration</h2>
<p>All properties changed from <code>get; set;</code> to <code>get; init;</code>.</p>
<pre><code class="language-cs">// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = &quot;;&quot;;

// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	Delimiter = &quot;;&quot;,
}
</code></pre>
<p><code>CsvConfiguration</code> changed from a <code>class</code> to a <code>record</code>.</p>
<pre><code class="language-cs">// v19
class MyConfig : CsvConfiguration {}

// v20
record MyConfig : CsvConfiguration {}
</code></pre>
<h3 id="shouldquote">ShouldQuote</h3>
<p><code>ShouldQuote</code> now takes in <code>IWriterRow</code> instead of <code>CsvContext</code>.</p>
<pre><code class="language-cs">// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	ShouldQuote = (field, row) =&gt; true,
};

// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	ShouldQuote = (field, context) =&gt; true,
};
</code></pre>
<h3 id="newline">NewLine</h3>
<p>Changed from <code>enum NewLines</code> to <code>char?</code>.</p>
<pre><code class="language-cs">// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	NewLine = NewLines.LF,
};

// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	NewLine = '\n',
};
</code></pre>
<h3 id="newlinestring">NewLineString</h3>
<p>This was removed. Any code referencing this should be deleted.</p>
<h3 id="registerclassmap">RegisterClassMap</h3>
<p>This moved to <code>CsvContext</code>.</p>
<pre><code class="language-cs">// v19
csv.Configuration.RegisterClassMap&lt;MyMap&gt;();

// v20
csv.Context.RegisterClassMap&lt;MyMap&gt;();
</code></pre>
<h3 id="unregisterclassmap">UnregisterClassMap</h3>
<p>This moved to <code>CsvContext</code>.</p>
<pre><code class="language-cs">// v19
csv.Configuration.UnregisterClassMap&lt;MyMap&gt;();

// v20
csv.Context.UnregisterClassMap&lt;MyMap&gt;();
</code></pre>
<h3 id="automap">AutoMap</h3>
<p>This moved to <code>CsvContext</code>.</p>
<pre><code class="language-cs">// v19
csv.Configuration.AutoMap&lt;MyType&gt;();

// v20
csv.Context.AutoMap&lt;MyType&gt;();
</code></pre>
<h2 id="iparserconfiguration">IParserConfiguration</h2>
<p>All setters removed.</p>
<pre><code class="language-cs">// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = &quot;;&quot;;

// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	Delimiter = &quot;;&quot;,
};
</code></pre>
<ul>
<li>Added <code>bool CacheFields</code>.</li>
<li>Added <code>bool LeaveOpen</code>.</li>
<li>Added <code>char? NewLine</code>.</li>
<li>Added <code>ParserMode Mode</code>.</li>
<li>Added <code>char[] WhiteSpaceChars</code>.</li>
<li>Removed <code>bool IgnoreQuotes</code>.</li>
</ul>
<p>Any classes that implement <code>IParserConfiguration</code> will need these changes.</p>
<h2 id="ireaderconfiguration">IReaderConfiguration</h2>
<p>All setters removed.</p>
<pre><code class="language-cs">// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = &quot;;&quot;;

// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	Delimiter = &quot;;&quot;,
};
</code></pre>
<ul>
<li>Removed <code>TypeConverterOptionsCache</code>.</li>
<li>Removed <code>TypeConverterCache</code>.</li>
<li>Removed <code>Maps</code>.</li>
<li>Removed <code>RegisterClassMap</code>.</li>
<li>Removed <code>UnregisterClassMap</code>.</li>
<li>Removed <code>AutoMap</code>.</li>
</ul>
<p>Any classes that implement <code>IReaderConfiguration</code> will need these changes.</p>
<h2 id="iserializerconfiguration">ISerializerConfiguration</h2>
<p>This interface was removed and it's properties were added to <code>IWriteConfiguration</code>.</p>
<pre><code class="language-cs">// v19
class MyConfig : ISerializerConfiguration {}

// v20
class MyConfig : IWriterConfiguration {}
</code></pre>
<h2 id="iwriterconfiguration">IWriterConfiguration</h2>
<p>All setters removed.</p>
<pre><code class="language-cs">// v19
var config = new CsvConfiguration(CultureInfo.InvariantCulture);
config.Delimiter = &quot;;&quot;;

// v20
var config = new CsvConfiguration(CultureInfo.InvariantCulture)
{
	Delimiter = &quot;;&quot;,
};
</code></pre>
<ul>
<li>Removed <code>QuoteString</code>.</li>
<li>Removed <code>TypeConverterCache</code>.</li>
<li>Removed <code>MemberTypes</code>.</li>
<li>Removed <code>Maps</code>.</li>
<li>Removed <code>RegisterClassMap</code>.</li>
<li>Removed <code>UnregisterClassMap</code>.</li>
<li>Removed <code>AutoMap</code>.</li>
</ul>
<p>Any classes that implement <code>IWriterConfiguration</code> will need these changes.</p>
<h2 id="membermap">MemberMap</h2>
<p><code>ConvertUsing</code> renamed to <code>Convert</code>.</p>
<pre><code class="language-cs">// v19
Map(m =&gt; m.Property).ConvertUsing(row =&gt; row.Get(0));
Map(m =&gt; m.Property).ConvertUsing(value =&gt; value?.ToString() ?? string.Empty);

// v20
Map(m =&gt; m.Property).Convert(row =&gt; row.Get(0));
Map(m =&gt; m.Property).Convert(value =&gt; value?.ToString() ?? string.Empty);
</code></pre>
<h2 id="csvparser">CsvParser</h2>
<p><code>string[] Read()</code> changed to <code>bool Read()</code>.</p>
<pre><code class="language-cs">// v19
string[] record;
while ((record = parser.Read()) != null)
{
}

// v20
while (parser.Read())
{
	// Only get fields you need.
	var field1 = parser[0];
	var field2 = parser[1];

	// Get all fields.
	var record = parser.Record;
}
</code></pre>
<p>Constructor paramter <code>IFieldReader fieldReader</code> removed from all constructors.</p>
<pre><code class="language-cs">// v19
var parser = new CsvParser(fieldReader);

// v20
var parser = new CsvParser();
</code></pre>
<h2 id="csvserializer">CsvSerializer</h2>
<p>Removed. Functionality moved into <code>CsvWriter</code>.</p>
<h2 id="ifieldreader">IFieldReader</h2>
<p>Removed. Functionality moved into <code>CsvParser</code>.</p>
<h2 id="iparser">IParser</h2>
<ul>
<li>Added <code>long ByteCount</code>.</li>
<li>Added <code>long CharCount</code>.</li>
<li>Added <code>int Count</code>.</li>
<li>Added <code>string this[int index]</code>.</li>
<li>Added <code>string[] Record</code>.</li>
<li>Added <code>string RawRecord</code>.</li>
<li>Added <code>int Row</code>.</li>
<li>Added <code>int RawRow</code>.</li>
<li>Changed <code>string[] Read</code> to <code>bool Read</code>.</li>
<li>Changed <code>Task&lt;string[]&gt; ReadAsync</code> to <code>Task&lt;bool&gt; ReadAsync</code>.</li>
</ul>
<p>Any classes that implement <code>IParser</code> will need these changes.</p>
<h2 id="ireader">IReader</h2>
<ul>
<li>Removed <code>ICsvParser Parser</code>.</li>
</ul>
<p>Any classes that implement <code>IReader</code> will need these changes.</p>
<h2 id="ireaderrow">IReaderRow</h2>
<ul>
<li>Added <code>int ColumnCount</code>.</li>
<li>Added <code>int CurrentIndex</code>.</li>
<li>Added <code>string[] HeaderRecord</code>.</li>
<li>Added <code>IParser Parser</code>.</li>
</ul>
<p>Any classes that implement <code>IReaderRow</code> will need these changes.</p>
<h2 id="iserializer">ISerializer</h2>
<p>Removed. Functionality moved into <code>IWriter</code>.</p>
<h2 id="iwriterrow">IWriterRow</h2>
<ul>
<li>Added <code>string[] HeaderRecord</code>.</li>
<li>Added <code>int Row</code>.</li>
<li>Added <code>int Index</code>.</li>
</ul>
<h2 id="recordbuilder">RecordBuilder</h2>
<p>Removed. Functionality moved into <code>CsvWriter</code>.</p>
<h2 id="caches">Caches</h2>
<p><code>enum Caches</code> was removed. Modifying internal caches is not supported anymore.
Any code referencing this should be removed.</p>
<h2 id="readingcontextwritingcontext">ReadingContext/WritingContext</h2>
<p><code>ReadingContext</code> and <code>WritingContext</code> was merged into a single <code>CsvContext</code>.
Anywhere either of these was used should change to <code>CsvContext</code>.</p>
<h2 id="funcaction">Func/Action</h2>
<p>Any place a <code>Func</code> or <code>Action</code> was used now has a dedicated <code>delegate</code>.
This should only affect classes that are inheriting <code>ClassMap</code>
or <code>CsvConfiguration</code>.</p>
<h2 id="csvfieldreader">CsvFieldReader</h2>
<p>Class removed. Code was wrapped into <code>CsvParser</code>.</p>

					</div>
				</div>
		</div>
	</main>

	<br /><br />

	<footer id="footer" class="footer">
	<div class="has-text-centered">&copy; 2009-2021 Josh Close</div>
</footer>



	<script>
		hljs.configure({
			tabReplace: "    "
		});
		hljs.initHighlightingOnLoad();
	</script>
	<script src="/CsvHelper/scripts/header.js"></script>
	<script src="/CsvHelper/scripts/sidebar.js"></script>
	
</body>
</html>
